﻿using System;
using System.Reflection;
using Glue;
using Xunit;

namespace GlueExamples.CompleteExamples
{
    public class BasicVerificationAndTesting
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        private class DomainPerson
        {
            public int Id { get; private set; }
            public String Name { get; set; }
            public DomainAddress Address { get; set; }
        }
        private class DomainAddress
        {
            public String StreetAddress { get; set; }
            public int ZipCode { get; set; }
            public String City { get; set; }
            public String Country { get; set; }
        }

        private class GuiPerson
        {
            public int Id { get { return 0;} set { return;} }
            public String Name { get; set; }
            public String StreetAddress { get; set; }
            public int ZipCode { get; set; }
            public String City { get; set; }
            public String Country { get; set; }
        }

        public BasicVerificationAndTesting()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();

            mapping.IgnoreTowards<GuiPerson>(gui=>gui.Id);
            mapping.Relate(domain => domain.Name, gui => gui.Name);

            var addressMapping = new Mapping<DomainAddress, GuiPerson>();
            addressMapping.AutoRelateEqualNames();

            mapping.Flatten(domain=>domain.Address,addressMapping);
        }

        [Fact]
        public void AsserAllPropertiesRelated()
        {
            mapping.GetRelationsVerification().AssertAllPropertiesRelated<GuiPerson>();
        }

        [Fact]
        public void AssertMappingWorks()
        {
            mapping.GetMapperVerification().AssertMapsCorrectlyTowards(new GuiPerson());
        }

    }

    
}
